# bytes的定义
buffer = b'abcdefghijklmn'
print(buffer,type(buffer),"len=",len(buffer))
print(buffer[2:9:2])

buffer = b'\x11\xff\x77'
print("%x"%(buffer[1]))

buffer = bytes(i+0x10 for i in range(10))
print(buffer)

# bytes的转换
x = 65534
# int的to_bytes()成员函数可以将一个整数转换成指定字节长度的bytes，第二个参数‘little’指明了字节编码顺序
bufferLittle = x.to_bytes(2,'little')
print("little endian:",bufferLittle)
bufferBig = x.to_bytes(2,'big')
print("big endian:",bufferBig)
# int的from_bytes()成员函数将bytes重新打包成Python的int对象
y = int.from_bytes(b'\xfe\xff','little')
print(y)